﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApTcIntegrationWrapper
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;


namespace DnProcessSimulateCommands;

internal class CApTcIntegrationWrapper : IDisposable
{
  private ITcSoaAssignDataFromTcService _service;

  public CApTcIntegrationWrapper()
  {
    this._service = (ITcSoaAssignDataFromTcService) new TcSoaAssignDataFromTcService();
  }

  public CApStructureSearchResultResponse StartSearch(
    string scopeUid,
    string itemIdSearchCriteria,
    string itemRevisionNameSearchCriteria,
    IEnumerable<string> allowedRevisionTypes,
    IEnumerable<string> requiredObjectProperties)
  {
    long finished;
    TcSoaModelObjectData[] objects;
    this._service.StartSearch(scopeUid, itemIdSearchCriteria, itemRevisionNameSearchCriteria, allowedRevisionTypes.ToArray<string>(), requiredObjectProperties.ToArray<string>(), out finished, out objects);
    return new CApStructureSearchResultResponse(finished != 0L, (IEnumerable<TcSoaModelObjectData>) objects);
  }

  public CApStructureSearchResultResponse NextSearch()
  {
    long finished;
    TcSoaModelObjectData[] objects;
    this._service.NextSearch(out finished, out objects);
    return new CApStructureSearchResultResponse(finished != 0L, (IEnumerable<TcSoaModelObjectData>) objects);
  }

  public void StopSearch() => this._service.StopSearch();

  public static string CalculateCloneStableIdChain(string objectUid)
  {
    TcSoaAssignDataFromTcService o = new TcSoaAssignDataFromTcService();
    string objectCloneStableIdChain;
    ((ITcSoaAssignDataFromTcService) o).ComputeCloneStableIdChain(objectUid, out objectCloneStableIdChain);
    Marshal.ReleaseComObject((object) o);
    return objectCloneStableIdChain;
  }

  public IDictionary<string, IDictionary<string, string>> GetObjectsProperties(
    IEnumerable<string> uids,
    IEnumerable<string> propertyNames)
  {
    TcSoaModelObjectData[] objects;
    this._service.GetProperties(uids.ToArray<string>(), propertyNames.ToArray<string>(), out objects);
    Dictionary<string, IDictionary<string, string>> objectsProperties = new Dictionary<string, IDictionary<string, string>>();
    foreach (TcSoaModelObjectData soaModelObjectData in objects)
    {
      Dictionary<string, string> dictionary = new Dictionary<string, string>();
      for (int index = 0; index < ((IEnumerable<string>) soaModelObjectData.propertyNames).Count<string>(); ++index)
      {
        string propertyName = soaModelObjectData.propertyNames[index];
        string propertyValue = soaModelObjectData.propertyValues[index];
        dictionary.Add(propertyName, propertyValue);
      }
      objectsProperties.Add(soaModelObjectData.uid, (IDictionary<string, string>) dictionary);
    }
    return (IDictionary<string, IDictionary<string, string>>) objectsProperties;
  }

  public void Dispose() => Marshal.ReleaseComObject((object) this._service);
}
